﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Metadata.Edm;
using System.Data;

namespace Arch.EF.Data
{
    public static class EntitySetExtentions
    {
        public static string GetIdProperty(this EntitySetBase entitySet)
        {
            return entitySet.ElementType.KeyMembers.First().Name;
        }

        public static EntityKey CreateEntityKey(this EntitySetBase entitySet, object id)
        {
            return new EntityKey(entitySet.EntityContainer.Name + "." + entitySet.Name,
              new[] { 
                  new EntityKeyMember(entitySet.ElementType.KeyMembers.Select(k => k.Name).FirstOrDefault(), id) 
              });
        }

        public static string GetFullName(this EntitySetBase entitySet)
        {
            return string.Format("{0}.{1}", entitySet.EntityContainer.Name, entitySet.Name);
        }
    }
}
